<!DOCTYPE html>
<html lang="cn" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <title>网站导航 nav Form</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" th:href="@{/statics/layui/css/layui.css}" media="all">
    <link rel="stylesheet" th:href="@{/statics/style/admin.css}" media="all">
    <style type="text/css">
        html{
            background-color: #FFF;
        }
        .pic {
            margin-left: 130px;
        }

        .pic dl {
            float: left;
            position: relative;
        }

        .pic dl dd {
            position: absolute;
            right: 5px;
            top: 5px;
            cursor: pointer;
            background: #666;
            color: #fff;
            padding: 2px;
        }

        .pic img {
            height: 100px;
            margin: 5px 0;
            margin-right: 5px;
        }

    </style>
</head>
<body>

<div class="layui-form" lay-filter="layuiadmin-form-nav" id="layuiadmin-form-nav" style="padding: 0px 5px;">
    <div class="layui-tab">
        <ul class="layui-tab-title">
            <li class="layui-this">基本选项</li>
            <li>高级选项</li>
        </ul>
        <div class="layui-tab-content">
            <div class="layui-tab-item layui-show">
                <div class="layui-form-item">
                    <label class="layui-form-label">上级导航</label>
                    <div class="layui-input-block">
                        <select name="pid">
                            <option value="0">顶级导航</option>
                            <option th:each="n:${navs}" th:value="${n.id}"
                                    th:selected="${n.id == nav.pid ? 'true':'false'}" th:text="${ '- ' + n.name}"/>
                        </select>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">导航名称</label>
                    <div class="layui-input-block">
                        <input type="text" name="name" lay-verify="required" autocomplete="off" placeholder="请输入导航名称"
                               class="layui-input" th:value="${nav.name}">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">菜单位置</label>
                    <div class="layui-input-block">
                        <select name="position">
                            <option th:value="top" th:selected="${'top' == nav.position ? 'true':'false'}">顶部菜单</option>
                            <option th:value="main" th:selected="${'main' == nav.position ? 'true':'false'}">主菜单</option>
                            <option th:value="bottom" th:selected="${'bottom' == nav.position ? 'true':'false'}">底部菜单</option>
                        </select>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">URL地址</label>
                    <div class="layui-input-block">
                        <input type="text" id="url" name="url" autocomplete="off" placeholder="请输入URL地址" class="layui-input"
                               th:value="${nav.url}">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">状态</label>
                    <div class="layui-input-block">
                        <input type="radio" name="state" value="1" title="显示" th:field="${nav.state}"/>
                        <input type="radio" name="state" value="0" title="隐藏" th:field="${nav.state}"/>
                    </div>
                </div>
            </div>
            <div class="layui-tab-item">
                <div class="layui-form-item">
                    <label class="layui-form-label">导航图标</label>
                    <div class="layui-input-block">
                        <input type="text" name="icon" autocomplete="off" placeholder="请输入图标" class="layui-input"
                               th:value="${nav.icon}">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">栏目大图</label>
                    <div class="layui-input-inline">
                        <input type="text" name="picture" id="picture" placeholder="请上传栏目大图" class="layui-input" th:value="${nav.picture}">
                    </div>
                    <button type="button" class="layui-btn upload" data-des="picture">
                        <i class="layui-icon">&#xe67c;</i>上传图片
                    </button>
                    <div id="pic_box" class="pic">
                        <dl th:if="${nav.picture}">
                            <dt><img th:src="${nav.picture}"
                                     th:data-url="${nav.picture}"></dt>
                            <dd>删除</dd>
                        </dl>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">排序序号</label>
                    <div class="layui-input-block">
                        <input type="text" name="sorting" lay-verify="required" autocomplete="off" placeholder="请输入排序序号"
                               class="layui-input" th:value="${nav.sorting}?:'255'">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">导航描述</label>
                    <div class="layui-input-block">
                        <textarea name="memo" placeholder="请输入栏目描述" class="layui-textarea">[[${nav.memo}]]</textarea>
                    </div>
                </div>
            </div>
        </div>
        <div class="layui-form-item layui-hide">
            <input type="hidden" name="id" th:value="${nav.id}" autocomplete="off" class="layui-input"/>
            <input type="hidden" name="lang" th:value="${nav.lang == null ? lang : nav.lang}" autocomplete="off" class="layui-input"/>
            <button class="layui-btn" lay-submit lay-filter="LAY-nav-add-submit" id="LAY-nav-add-submit">提交</button>
        </div>
    </div>
</div>
    <script th:src="@{/statics/layui/layui.js}"></script>
    <script>
        layui.config({
            base: '/statics/' //静态资源所在路径
        }).extend({
            index: 'lib/index' //主入口模块
        }).use(['index', 'form', 'upload'], function () {
            var $ = layui.$
                , form = layui.form
                , upload = layui.upload;

            upload.render({
                elem: '.upload'
                , url: '/api/file/local/upload'
                , accept: 'images'
                , method: 'post'
                , multiple: false //多文件上传
                , acceptMime: 'image/*'
                ,before: function(obj){
                    layer.load(); //上传loading
                }
                ,done: function(res){
                    var item = this.item;
                    var des=$(item).data('des');
                    layer.closeAll('loading'); //关闭loading
                    if(res.code==0){
                        $('#'+des).val(res.data);
                        layer.msg('上传成功！');
                    }else{
                        layer.msg('上传失败！');
                    }
                }
                ,error: function(){
                    layer.closeAll('loading'); //关闭loading
                    layer.msg('上传发生错误！');
                }
            });

        })
    </script>
</body>
</html>